home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: Int to Double, Pl Advise!
- Date: 29 Mar 1996 18:03:01 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4jh8kl$g5v@sparcserver.lrz-muenchen.de>
- References: <isa5224.544.315B647A@age2.age.uiuc.edu>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- isa5224@age2.age.uiuc.edu (Irfan S. Ahmad) writes:
-
- >Hi:
-
- >I am having problems with the following type conversion. From int to double.
- >If someone can comment:
-
- >#define Ng 4
- >#define Nr 4
-
- >#include <stdio.h>
- >#include <math.h>
- >#include <malloc.h>
-
- May including this header changes the meaning of all statements
- that follow. I will assume that this is not the case, i.e. that
- this header was _not_ included.
-
- >int p0[Ng][Nr];
-
- >int main(){
- >int i,j,k;
- >float x =0;
- >float y =0;
- >:
- >for (i=1; i<Ng; i++) {
- > for (j=1; j<Nr; j++) {
- >
- > x = x + ((double) p0[i,j]) / (double)(j*j); }
-
- "p0[i,j]" is equivalent to "p0[j]", the only difference is that
- "i" is evaluated, too. If the evaluation of "i" has any side
- effects (which I doubt in your example), the statements are
- different, otherwise the are equivalent.
-
- "p[j]" is an "array of Nr doubles". Unfortunately, C does not
- do the obvious thing in this situation, i.e. divide all elements
- of the array by the second operand of "/". Some matrix or vector
- oriented languages are defined that way, but C is not such a
- language.
-
- >}
-
- >I get the following compilation error(s) on MS C++ compiler:
- >error C2440: 'cast' : cannot convert from 'int [4]' to 'double '
- >
-
- >Please post or preferably email your comments to:
-
- If you want to contribute something to reducing the noise level
- in this group, post your question, ask for email replies, _and_
- offer to post a summary of the answers you got. If you want
- private tutition, pay for it.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-